<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">

    <script src="/web/js/vue2.js"></script>
    <script src="/web/js/axios.min.js"></script>
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>

<body>
<div style="margin: 20px" id="root">
    <template v-for="e of trans">
        <el-collapse v-model="activeName" accordion>
            <el-button @click="doShow(e)" size="mini" type="primary" icon="el-icon-edit" circle></el-button>
            <el-collapse-item :title="e.title" :name="e.id">

                <div>{{e.content}}</div>
            </el-collapse-item>

        </el-collapse>
    </template>


    <!--嵌套的修改内容-->
    <el-dialog title="编辑" :visible.sync="dialogFormVisible">
        <el-form :model="form">
            <el-form-item label="标题" :label-width="formLabelWidth">
                <el-input v-model="form.title" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="内容" :label-width="formLabelWidth">
                <el-input autosize type="textarea" v-model="form.content"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="doUpdate">确 定</el-button>
        </div>
    </el-dialog>
</div>


<script>

    const vm = new Vue({
        el: "#root",
        data() {
            return {
                trans: [],
                activeName: 0,
                dialogFormVisible: false,
                form: {
                    id: "",
                    title: "",
                    content: "",
                },
                formLabelWidth: '120px'
            }
        },
        methods: {
            doShow(e) {
                this.dialogFormVisible = true;
                this.form.id = e.id;
                this.form.title = e.title;
                this.form.content = e.content;
                // alert(id);
            },
            doUpdate() {
                axios.post("/trans/update", this.form)
                this.dialogFormVisible=false;
                window.parent.location.reload();
            }
        },
        async mounted() {
            let res = await axios.get("/trans/list")
            this.trans = res.data.data;
            console.log(this.trans);
        }
    })
</script>

</body>
</html>